package tests;

import static org.junit.Assert.*;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import cruncher.Solution;
import cruncher.Utils;
import cruncher.Variable;

public class SolutionTester {

	Solution sol = null;
	
	@Before
	public void setUp() throws Exception {
		sol = new Solution(0.0);
	}

	@After
	public void tearDown() throws Exception {
		sol = null;
	}

	@Test
	public void testSetValues() throws Exception {
		int num = 10;
		for (int x=0; x < num; x++)
		{
			sol.add(new Variable("A"+x,Utils.TYPE_INTEGER,1.0));
		}
		assertTrue(sol.size() == num);
	}
	
	@Test
	public void testGetValues() throws Exception {
		int num = 10;
		for (int x=0; x < num; x++)
		{
			sol.add(new Variable("A"+x,Utils.TYPE_INTEGER,1.0));
		}
		
		int size = 0;
		for (Variable var : sol)
		{
			size++;
		}
		assertTrue(size == num);
			
	}
	
	@Test
	public void testGetIntegerValues() throws Exception {
		sol.add(new Variable("A",Utils.TYPE_INTEGER,1.0));
		sol.add(new Variable("B",Utils.TYPE_INTEGER,1.0));
		sol.add(new Variable("C",Utils.TYPE_FRACTIONAL,1.0));
		
		assertTrue(sol.getDecisionVariables().size()==2);
	}

	@Test
	public void testCompare() throws Exception {
		sol.add(new Variable("A",Utils.TYPE_INTEGER,1.0));
		sol.add(new Variable("B",Utils.TYPE_INTEGER,1.0));
		
		assertTrue(sol.compareTo(sol)==0);
		Solution sol2 = new Solution(1.0);
		assertTrue(sol.compareTo(sol2) < 0);
		assertTrue(sol2.compareTo(sol) > 0);
	}
}
